package com.csweimei.rentmanagementtreasure.tenant.viewModel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.csweimei.rentmanagementtreasure.http.Repository;
import com.csweimei.rentmanagementtreasure.http.entity.TabThreeBean;
import com.github.mikephil.charting.formatter.IFillFormatter;

import java.util.Map;

import io.reactivex.observers.DisposableObserver;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class FThreeVM extends BaseViewModel<Repository> {
    public FThreeVM(@NonNull Application application, Repository model) {
        super(application, model);
    }

    @Override
    public void onResume() {
        super.onResume();
        getNoticeData();
    }


    public ObservableList<TabThreeItemVM> observableList = new ObservableArrayList<>();
    public ItemBinding<TabThreeItemVM> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_three_notice);
    private void getNoticeData() {
        model.message_center(AppConfig.getCurMap(model))
                .compose(RxUtils.schedulersTransformer())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(this)
                .subscribe(new DisposableObserver<TabThreeBean>() {
                    @Override
                    public void onNext(TabThreeBean o) {
                        observableList.clear();
                        if (o.issucc){
                            for (TabThreeBean.DataDTO bean : o.getData()) {
                                TabThreeItemVM tabThreeItemVM = new TabThreeItemVM(FThreeVM.this);
                                tabThreeItemVM.setData(bean);
                                observableList.add(tabThreeItemVM);
                            }
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void lookMsg(String type){
        Map<String,String> map = AppConfig.getCurMap(model);
        map.put("messageType",type);
        model.edit_message(map)
                .compose(RxUtils.exceptionTransformer())
                .compose(RxUtils.schedulersTransformer())
                .doOnSubscribe(this)
                .subscribe(new DisposableObserver() {
                    @Override
                    public void onNext(Object o) {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
